package com.gwz.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gwz.sys.domain.Notice;
import com.gwz.sys.mapper.NoticeMapper;
import com.gwz.sys.service.NoticeService;
import com.gwz.sys.utils.DataGridView;
import com.gwz.sys.vo.NoticeVo;

@Service
@Transactional
public class NoticeServiceImpl implements NoticeService {

	@Autowired
	private NoticeMapper noticeMapper;
	
	@Override
	public DataGridView queryAllNotice(NoticeVo noticeVo) {
		Page<Object> page = PageHelper.startPage(noticeVo.getPage(), noticeVo.getLimit());
		List<Notice> data = noticeMapper.queryAllNotice(noticeVo);
		return new DataGridView(page.getTotal(), data);
	}

	@Override
	public void deleteNotice(NoticeVo noticeVo) {
		noticeMapper.deleteByPrimaryKey(noticeVo.getId());
	}

	@Override
	public void addNotice(NoticeVo noticeVo) {
		noticeMapper.insertSelective(noticeVo);
	}

	@Override
	public Notice queryNoticeByNoticeId(Integer noticeId) {
		return noticeMapper.selectByPrimaryKey(noticeId);
	}

	@Override
	public void updateNotice(NoticeVo noticeVo) {
		noticeMapper.updateByPrimaryKeySelective(noticeVo);
	}

	@Override
	public void batchDelete(NoticeVo noticeVo) {
		Integer[] ids = noticeVo.getIds();
		for (Integer id : ids) {
			noticeMapper.deleteByPrimaryKey(id);
		}
	}

}
